//
//  BasicViewController.m
//  EHour
//
//  Created by wuxian on 13-9-6.
//  Copyright (c) 2013年 wuxian. All rights reserved.
//

#import "BasicViewController.h"
#import "AppDelegate.h"

@interface BasicViewController(){
    BOOL _hasLoad;
}
@end

@implementation BasicViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 66)];
    self.navView = navView;
    [self.view addSubview:self.navView];
    [self.navView setHidden:_isHiddenNavView];
    
    UIImageView *navBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 46)];
    navBG.image = [UIImage imageNamed:@"nav_bg.png"];
    [self.navView addSubview:navBG];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, self.navView.frame.size.height-33, self.navView.frame.size.width-60, 22)];
    [titleLabel setTextColor:[UIColor whiteColor]];
    titleLabel.font = [UIFont systemFontOfSize:20];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.backgroundColor = [UIColor clearColor];
    self.navLabel = titleLabel;
    [self.navView addSubview:titleLabel];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(10, self.navView.frame.size.height-38, 60, 30);
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back_n.png"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    backBtn.tag = 100;
    [self.navView addSubview:backBtn];
    backBtn.hidden = _isRootVC;

    if (IOS7_OR_LATER) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    if (!_hasLoad){
        if (self.navStr) {
            self.navLabel.text = self.navStr;
        }
        _hasLoad = YES;
    }

}

- (void)backBtnAct:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
